package com.blog.interceptor.init;

import java.text.DateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 创建存储用户的session
 * @author Administrator
 *
 */
public class LoginSession extends HandlerInterceptorAdapter{
	private final Logger log = Logger.getLogger(getClass());

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		// TODO 自动生成的方法存根
		HttpSession session = request.getSession();
		session.setMaxInactiveInterval(1800);
		session.setAttribute("username",null);
		 
		String creationTime = DateFormat.getTimeInstance().format(session.getCreationTime());
		log.info("用户session已创建，创建时间："+creationTime);
		return true;
	}
	 
 

 
 
	
}
